Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularize zkBob pool and add energy redeemer example #78

Merged
merged 6 commits into from
Sep 5, 2023

Conversation

k1rill-fedoseev
Copy link
Collaborator

@k1rill-fedoseev k1rill-fedoseev commented Jun 28, 2023

This PR simplifies logic of core ZkBobPool contract, by extracting limits, accounting, and KYC logic into an external contract.

Changelog

Changes in the ZkBobPool interface:

  • zkBobPool.getLimitsFor(...) -> zkBobPool.accounting().getLimitsFor(...)
  • zkBobPool.kycProvidersManager() -> zkBobPool.accounting().kycProvidersManager()
  • All admin functions for managing limits, tiers and KYC are also moved to accounting module
    Changes in denomination:
  • Admin function accounting.setLimits(...) now expects values in zkBob units, without denominator

Migration details

There are a few data structures that are being deprecated during the migration:

  • Pool stats: slot0 and slot1. These should be copied to the new module during the migration.
  • Tier limits. This should be re-initialized in the new module during the migration.
  • KYC Manager configuration. This should be re-initialized in the new module during the migration.
  • User tiers. These should be re-initialized in the new module during the migration.
  • Pool daily usage counters. These can be safely skipped during the migration, as they are not meant to be persistent.
  • Auxiliary snapshots. These can be safely skipped during the migration, with little to no impact to maxWeeklyAvgTvl and maxWeeklyTxCount stats.

@k1rill-fedoseev k1rill-fedoseev self-assigned this Jul 12, 2023
@k1rill-fedoseev k1rill-fedoseev requested a review from akolotov July 12, 2023 10:34
@k1rill-fedoseev k1rill-fedoseev marked this pull request as ready for review July 12, 2023 10:34
* @param _maxWeeklyAvgTvl max seen average tvl over period of at least 1 week, might not be precise.
*/
function initialize(
uint32 _txCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to copy this state from the pool contract during initialisation rather than specify them manually?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to include logic for raw storage reads in the main contract, so instead I placed it in the one-time migration contract. I think it's a bit safer and flexible approach overall.

In case we will ever again need to redeploy accounting module (e.g. to change limits logic), such generic initialization logic would be also helpful.

src/zkbob/utils/ZkBobAccounting.sol Outdated Show resolved Hide resolved
@@ -329,7 +324,10 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
*/
function recordDirectDeposit(address _sender, uint256 _amount) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to call recordOperation from the queue contract directly? What is the goal of having this functionality in the pool contract?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to keep it this way, to reduce dependencies between pool modules. It potentially simplifies future upgrades, as there less address pointers being used between various contracts and permission logic in contract becomes simpler.

src/zkbob/ZkBobPoolUSDCMigrated.sol Outdated Show resolved Hide resolved
@akolotov akolotov merged commit 08b974b into develop Sep 5, 2023
3 checks passed
@akolotov akolotov deleted the feat/energy-redeemer branch September 5, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants